var dayNames = Array("monday","tuesday","wednesday","thursday","friday");
var boxWidth=0;
var boxHeight=0;
    function drawSchedule() {
	for(var i in dayNames)
	$("#schedule").append('<div id='+dayNames[i]+' style =  "font-size:20px;border-left:1px solid #999; position: absolute; z-index: 99; height:102%; left:'+ (6+19*i) +'%; top: 0%;  width: 19%">'+dayNames[i]+'</div>');
	
	for(i=0;i<14;i++)
	$("#schedule").append('<div id='+i+' style =  "border-top:1px solid #999; font-size: 20px; position: absolute; z-index: 99; width:102%; left:0%; top: '+(i*7+6)+'%; height:7%;">'+((i+7)%12+1)+'</div>');

    }
var response;
var numClass;
function drawAllClasses(n){
n=Math.abs(n);
document.getElementById("classContainer").innerHTML = "";

var c = getRandColor();
document.getElementById("controls").innerHTML="<h3>you are viewing answer set "+Math.abs((numClass%response.length)+1)+' of '+(response.length>100 ? "100+" :response.length)+'</h3> <div id="hide3"><input type="button" value="last schedule" onclick="drawAllClasses(numClass--);"></div><div id="hide2"><input type="button" value="next schedule" onclick="drawAllClasses(numClass++);"></div> <h3>uniques involved</h3>';

var thisunique="";
var thisSet=response[n%response.length];
for(i in thisSet){
	if(response[0][i][0]!=thisunique){
		document.getElementById("controls").innerHTML=document.getElementById("controls").innerHTML+"<br>"+abbreviation(thisSet[i][0])+" : "+thisSet[i][1];
		thisunique=response[0][i][0];
		c = getRandColor();
		}
	
	DrawClass(thisSet[i][2],thisSet[i][3],thisSet[i][4],thisSet[i][0],c,thisSet[i][1]);
	}
}
var classid=0;
var ays = Array("m","t","w","th","f");
function getRandColor(){
return "rgb("+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+")";
}

function DrawClass(day,start,end,nam,c,unique){
	if(nam!=undefined && nam!="not found"){
	var x=ays.indexOf(day)*19+6;
	var y=((start/100)-8)*7+6; 
	$("#classContainer").append('<div id="class'+(classid)+'" style="background:'+c+'">'+abbreviation(nam)+'</div>');
	$("#class"+classid).css({border: '1px solid #999',                       
                       position: 'absolute',
		       'border-radius': '5px',
                       'z-index': 100,
		       'font-size': "30px",
			 'text-outline': '1px 1px #fff',
                       left: x+'%', top: y+'%',
                       width: '19%', height: 7*(end-start)/100+'%'});

	classid++;

}
}
function abbreviation(string){
	for(var i=4;i<7;i++)
		if("0123456789".indexOf(string[i])==-1)
			return string.substring(0,i);

	return string.substring(0,4);
}

